home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_msql.idb / usr / freeware / msql / tests / killer.z / killer
Encoding:
Text File  |  1998-10-28  |  10.3 KB  |  456 lines

  1. #!/bin/sh
  2. #
  3. #  This is a killer test that produces timing results in msql.times
  4. #  It's run as "killer <dbName>" where dbName is an existing database
  5. #  in which it does it's thing.  It creates, drops and generally
  6. #  beats up on a table called "test" within the given database so
  7. #  run it somewhere that you don't have a test table.
  8. #
  9. #  You may need to change a couple of the definitions below depending
  10. #  on how you`re setup (eg "/var/adm/msqld.pid"  and  "bc -l")
  11. #
  12. #  The script tries to determine what sort of /bin/time you have and
  13. #  works properly with either a SysV or BSD styled time.
  14. #
  15. #                            Bambi
  16.  
  17.  
  18. CREATE_INDEX="create unique index idx1 on test (num)"
  19. CREATE_TABLE="create table test ( name char(40), num int)"
  20. DROP="drop table test"
  21. DELETE="delete from test"
  22.  
  23. MSQL_HOME=/usr/freeware/msql
  24. TMP_FILE="$MSQL_HOME/tests/msql_test.out"
  25. RES_FILE="$MSQL_HOME/tests/msql.times"
  26.  
  27. DB=$1
  28. NUM_TESTS=2
  29. NUM_INSERTS=10000
  30. NUM_SELECTS=25000
  31. SEQ_SELECTS=2000
  32.  
  33. CALC="/usr/bin/bc -l"
  34. PID_FILE="$MSQL_HOME/msql2d.pid"
  35.  
  36. #MSQL_HOST="-h fawn"
  37.  
  38. MSQL="$MSQL_HOME/bin/msql $MSQL_HOST"
  39. MSQL_ADMIN="$MSQL_HOME/bin/msqladmin $MSQL_HOST"
  40.  
  41. #MSQL="/usr/local/Hughes/bin/msql $MSQL_HOST"
  42. #MSQL_ADMIN="/usr/local/Hughes/bin/msqladmin $MSQL_HOST"
  43.  
  44. PROFILE="N"
  45. GRAND_TOTAL=0
  46.  
  47. if test "$DB." = "."
  48. then
  49.     echo 
  50.     echo "Bad usage.  Please read the intro to the script."
  51.     echo
  52.     exit 1
  53. fi
  54.  
  55. #
  56. # Print the output file header
  57. #
  58.  
  59. echo "mSQL Killer Test.     Test machine = `uname -a`" > $RES_FILE
  60. $MSQL_ADMIN version | grep "server version" >> $RES_FILE
  61. echo "------------------------------------------------------------" >> $RES_FILE
  62. echo >> $RES_FILE
  63. echo >> $RES_FILE
  64.  
  65. #
  66. # Try to find time.  Linux may have it in /usr/bin
  67. #
  68. if test -f /bin/time
  69. then
  70.     BIN_TIME="/bin/time"
  71. else
  72.     if test -f /usr/bin/time
  73.     then
  74.         BIN_TIME="/usr/bin/time"
  75.     else
  76.         if test -f /usr/sbin/time
  77.         then
  78.             BIN_TIME="/usr/sbin/time"
  79.         fi
  80.     fi
  81. fi
  82.  
  83. if test "$BIN_TIME." = "."
  84. then
  85.     echo "Can't find /bin/time, /usr/bin/time or /usr/sbin/time"
  86.     echo "Timing details ar not available"
  87.     BIN_TIME=""
  88.     echo "time not found.  No timing details available" >> $RES_FILE
  89.     echo >> $RES_FILE
  90.     echo >> $RES_FILE
  91. else
  92.     echo "Using $BIN_TIME for timing calculations"
  93.     $BIN_TIME --version >/dev/null  2>&1
  94.     if test $? -eq 0
  95.     then
  96.         echo "$BIN_TIME is actually GNU time.  Using --portability."
  97.         BIN_TIME="$BIN_TIME --portability"
  98.     fi
  99. fi
  100.  
  101.  
  102.  
  103. #
  104. # What sort of /bin/time do we have?
  105. #
  106.  
  107. if test `$BIN_TIME /bin/test 2>&1 | wc -l` -gt 1
  108. then
  109.     echo "$BIN_TIME produces System V styled output."
  110.     TIME_CALC="(grep -i \"^real\" | awk '{ print \$2 }')"
  111. else
  112.     echo "$BIN_TIME produces BSD styled output."
  113.     TIME_CALC="awk '{ print \$1 }'"
  114. fi
  115.  
  116.  
  117.  
  118. #########################################################################
  119. # Insert into a new keyed table
  120. #
  121.  
  122. COUNT=0
  123. rm -f $TMP_FILE
  124. TOTAL=0
  125. if test "$PROFILE." = "Y."
  126. then
  127.     kill -INT `cat $PID_FILE`
  128.     sleep 1
  129.     $MSQL_HOME/bin/msql2d&
  130.     sleep 1
  131. fi
  132. echo "Inserting $NUM_INSERTS rows into new keyed table gave :-" >> $RES_FILE
  133. while test $COUNT -lt $NUM_TESTS
  134. do
  135.     echo "Dropping test table"
  136.     echo "$DROP \p\g" | ($MSQL $DB > /dev/null)
  137.     echo "Creating keyed table"
  138.     echo "$CREATE_TABLE \p\g" | ($MSQL $DB > /dev/null)
  139.     echo "$CREATE_INDEX \p\g" | ($MSQL $DB > /dev/null)
  140.     echo "Inserting $NUM_INSERTS rows into keyed table"
  141.     $BIN_TIME $MSQL_HOME/tests/insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE 3>/dev/tty
  142.     if test $? -ne 0
  143.     then
  144.         echo
  145.         echo "Test failed!  Aborting."
  146.         echo
  147.         exit 1
  148.     fi
  149.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  150.     echo "    $TIME seconds real time" >> $RES_FILE
  151.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  152.     COUNT=`expr $COUNT + 1`
  153.     echo "Inserts took $TIME seconds"
  154. done
  155.  
  156. echo >> $RES_FILE
  157. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC | sed "s/\..*//"`
  158. echo "    Total time = $TOTAL" >> $RES_FILE
  159. echo "    Average operations per second = $AVG" >> $RES_FILE
  160. GRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`
  161.  
  162. if test "$PROFILE." = "Y."
  163. then
  164.     kill -INT `cat $PID_FILE`
  165.     sleep 1
  166.     echo >> $RES_FILE
  167.     echo >> $RES_FILE
  168.     prof $MSQL_HOME/bin/msql2d | head -10 >> $RES_FILE
  169. fi
  170.  
  171. echo >> $RES_FILE
  172. echo >> $RES_FILE
  173. echo >> $RES_FILE
  174. echo >> $RES_FILE
  175.  
  176.  
  177. #########################################################################
  178. # Filling a deleted keyed table
  179. #
  180.  
  181. COUNT=0
  182. rm -f $TMP_FILE
  183. TOTAL=0
  184. if test "$PROFILE." = "Y."
  185. then
  186.     $MSQL_HOME/bin/msql2d&
  187.     sleep 1
  188. fi
  189. echo "Filling a deleted keyed table with $NUM_INSERTS rows gave :-" >> $RES_FILE
  190. while test $COUNT -lt $NUM_TESTS
  191. do
  192.     echo "Deleting contents of keyed table"
  193.     echo "$DELETE \p\g" | ($MSQL $DB > /dev/null)
  194.     echo "Filling data holes with $NUM_INSERTS inserts."
  195.     $BIN_TIME $MSQL_HOME/tests/insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE
  196.     if test $? -ne 0
  197.     then
  198.         echo
  199.         echo "Test failed!  Aborting."
  200.         echo
  201.         exit 1
  202.     fi
  203.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  204.     echo "    $TIME seconds real time" >> $RES_FILE
  205.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  206.     COUNT=`expr $COUNT + 1`
  207.     echo "Inserts took $TIME seconds."
  208. done
  209.  
  210. echo >> $RES_FILE
  211. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  212. echo "    Total time = $TOTAL" >> $RES_FILE
  213. echo "    Average operations per second = $AVG" >> $RES_FILE
  214. GRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`
  215.  
  216. if test "$PROFILE." = "Y."
  217. then
  218.     kill -INT `cat $PID_FILE`
  219.     sleep 1
  220.     echo >> $RES_FILE
  221.     echo >> $RES_FILE
  222.     prof $MSQL_HOME/bin/msql2d | head -10 >> $RES_FILE
  223. fi
  224.  
  225. echo >> $RES_FILE
  226. echo >> $RES_FILE
  227. echo >> $RES_FILE
  228. echo >> $RES_FILE
  229.  
  230.  
  231.  
  232.  
  233.  
  234. #########################################################################
  235. # Selecting from a keyed table
  236. #
  237.  
  238. COUNT=0
  239. rm -f $TMP_FILE
  240. TOTAL=0
  241. if test "$PROFILE." = "Y."
  242. then
  243.     $MSQL_HOME/bin/msql2d&
  244.     sleep 1
  245. fi
  246. echo "Selecting $NUM_SELECTS rows using primary key :-" >> $RES_FILE
  247. while test $COUNT -lt $NUM_TESTS
  248. do
  249.     echo "Selecting $NUM_SELECTS rows from a keyed table"
  250.     $BIN_TIME $MSQL_HOME/tests/select_test $MSQL_HOST $DB $NUM_SELECTS 2> $TMP_FILE
  251.     if test $? -ne 0
  252.     then
  253.         echo
  254.         echo "Test failed!  Aborting."
  255.         echo
  256.         exit 1
  257.     fi
  258.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  259.     echo "    $TIME seconds real time" >> $RES_FILE
  260.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  261.     COUNT=`expr $COUNT + 1`
  262.     echo "Selects took $TIME seconds"
  263. done
  264.  
  265. echo >> $RES_FILE
  266. AVG=`echo "($NUM_SELECTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  267. echo "    Total time = $TOTAL" >> $RES_FILE
  268. echo "    Average operations per second = $AVG" >> $RES_FILE
  269. GRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`
  270.  
  271. if test "$PROFILE." = "Y."
  272. then
  273.     kill -INT `cat $PID_FILE`
  274.     sleep 1
  275.     echo >> $RES_FILE
  276.     echo >> $RES_FILE
  277.     prof $MSQL_HOME/bin/msql2d | head -10 >> $RES_FILE
  278. fi
  279.  
  280. echo >> $RES_FILE
  281. echo >> $RES_FILE
  282. echo >> $RES_FILE
  283. echo >> $RES_FILE
  284.  
  285.  
  286.  
  287.  
  288.  
  289. #########################################################################
  290. # Insert into a new flat table
  291. #
  292.  
  293. COUNT=0
  294. rm -f $TMP_FILE
  295. TOTAL=0
  296. if test "$PROFILE." = "Y."
  297. then
  298.     $MSQL_HOME/bin/msql2d&
  299.     sleep 1
  300. fi
  301. echo "Inserting $NUM_INSERTS rows into new flat table gave :-" >> $RES_FILE
  302. while test $COUNT -lt $NUM_TESTS
  303. do
  304.     echo "Dropping test table"
  305.     echo "$DROP \p\g" | ($MSQL $DB > /dev/null)
  306.     echo "Creating flat table"
  307.     echo "$CREATE_TABLE \p\g" | ($MSQL $DB > /dev/null)
  308.     echo "Inserting $NUM_INSERTS rows into flat table"
  309.     $BIN_TIME $MSQL_HOME/tests/insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE
  310.     if test $? -ne 0
  311.     then
  312.         echo
  313.         echo "Test failed!  Aborting."
  314.         echo
  315.         exit 1
  316.     fi
  317.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  318.     echo "    $TIME seconds real time" >> $RES_FILE
  319.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  320.     COUNT=`expr $COUNT + 1`
  321.     echo "Inserts took $TIME seconds."
  322. done
  323.  
  324. echo >> $RES_FILE
  325. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  326. echo "    Total time = $TOTAL" >> $RES_FILE
  327. echo "    Average operations per second = $AVG" >> $RES_FILE
  328. GRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`
  329.  
  330. if test "$PROFILE." = "Y."
  331. then
  332.     kill -INT `cat $PID_FILE`
  333.     sleep 1
  334.     echo >> $RES_FILE
  335.     echo >> $RES_FILE
  336.     prof $MSQL_HOME/bin/msql2d | head -10 >> $RES_FILE
  337. fi
  338.  
  339. echo >> $RES_FILE
  340. echo >> $RES_FILE
  341. echo >> $RES_FILE
  342. echo >> $RES_FILE
  343.  
  344.  
  345. #########################################################################
  346. # Filling a flat table
  347. #
  348.  
  349. COUNT=0
  350. rm -f $TMP_FILE
  351. TOTAL=0
  352. if test "$PROFILE." = "Y."
  353. then
  354.     $MSQL_HOME/bin/msql2d&
  355.     sleep 1
  356. fi
  357. echo "Filling a deleted flat table with $NUM_INSERTS rows gave :-" >> $RES_FILE
  358. while test $COUNT -lt $NUM_TESTS
  359. do
  360.     echo "Deleting contents of flat table"
  361.     echo "$DELETE \p\g" | ($MSQL $DB > /dev/null)
  362.     echo "Filling data holes with $NUM_INSERTS inserts."
  363.     $BIN_TIME $MSQL_HOME/tests/insert_test $MSQL_HOST $DB $NUM_INSERTS 2> $TMP_FILE
  364.     if test $? -ne 0
  365.     then
  366.         echo
  367.         echo "Test failed!  Aborting."
  368.         echo
  369.         exit 1
  370.     fi
  371.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  372.     echo "    $TIME seconds real time" >> $RES_FILE
  373.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  374.     COUNT=`expr $COUNT + 1`
  375.     echo "Inserts took $TIME seconds"
  376. done
  377.  
  378. echo >> $RES_FILE
  379. AVG=`echo "($NUM_INSERTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  380. echo "    Total time = $TOTAL" >> $RES_FILE
  381. echo "    Average operations per second = $AVG" >> $RES_FILE
  382. GRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`
  383.  
  384. if test "$PROFILE." = "Y."
  385. then
  386.     kill -INT `cat $PID_FILE`
  387.     sleep 1
  388.     echo >> $RES_FILE
  389.     echo >> $RES_FILE
  390.     prof $MSQL_HOME/bin/msql2d | head -10 >> $RES_FILE
  391. fi
  392.  
  393. echo >> $RES_FILE
  394. echo >> $RES_FILE
  395. echo >> $RES_FILE
  396. echo >> $RES_FILE
  397.  
  398.  
  399.  
  400. #########################################################################
  401. # Selecting from a flat table
  402. #
  403.  
  404. COUNT=0
  405. rm -f $TMP_FILE
  406. TOTAL=0
  407. if test "$PROFILE." = "Y."
  408. then
  409.     $MSQL_HOME/bin/msql2d&
  410.     sleep 1
  411. fi
  412. echo "Selecting $SEQ_SELECTS rows without a key :-" >> $RES_FILE
  413. while test $COUNT -lt $NUM_TESTS
  414. do
  415.     echo "Selecting $SEQ_SELECTS rows from a flat table"
  416.     $BIN_TIME $MSQL_HOME/tests/select_test $MSQL_HOST $DB $SEQ_SELECTS 2> $TMP_FILE
  417.     if test $? -ne 0
  418.     then
  419.         echo
  420.         echo "Test failed!  Aborting."
  421.         echo
  422.         exit 1
  423.     fi
  424.     TIME=`(eval $TIME_CALC) < $TMP_FILE`
  425.     echo "    $TIME seconds real time" >> $RES_FILE
  426.     TOTAL=`echo "$TOTAL + $TIME" | $CALC`
  427.     COUNT=`expr $COUNT + 1`
  428.     echo "Selects took $TIME seconds"
  429. done
  430.  
  431. echo >> $RES_FILE
  432. AVG=`echo "($NUM_SELECTS * $NUM_TESTS) / $TOTAL" | $CALC| sed "s/\..*//"`
  433. echo "    Total time = $TOTAL" >> $RES_FILE
  434. echo "    Average operations per second = $AVG" >> $RES_FILE
  435. GRAND_TOTAL=`echo "$GRAND_TOTAL + $TOTAL" | $CALC`
  436.  
  437. if test "$PROFILE." = "Y."
  438. then
  439.     kill -INT `cat $PID_FILE`
  440.     sleep 1
  441.     echo >> $RES_FILE
  442.     echo >> $RES_FILE
  443.     prof $MSQL_HOME/bin/msql2d | head -10 >> $RES_FILE
  444. fi
  445.  
  446. echo >> $RES_FILE
  447. echo >> $RES_FILE
  448. echo "Total execution time = $GRAND_TOTAL" >> $RES_FILE
  449. echo >> $RES_FILE
  450. echo >> $RES_FILE
  451.  
  452. echo
  453. echo
  454. echo "Total execution time = $GRAND_TOTAL" 
  455. echo
  456.